package com.lgz.dbcourse.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @Author: LGZ
 * @Date: 2021/4/13 14:56
 * @Description:
 */
public class MainFrame extends MyFrame {



    public void start() {
        this.setVisible(true);
    }

    public MainFrame() {
        super("选择操作系统");
        this.setSize(700, 500);
        this.getContentPane().setLayout(null);
        this.setLocationRelativeTo(null);
        JButton userButton = new JButton(USER);
        JButton staffButton = new JButton(STAFF);
        userButton.setBounds(200, 200, 80, 30);
        staffButton.setBounds(400, 200, 80, 30);

        JLabel label = new JLabel("请选择操作系统");
        label.setBounds(300, 150, 200, 30);

        userButton.addActionListener(new ButtonChoseModel());
        staffButton.addActionListener(new ButtonChoseModel());

        this.add(userButton);
        this.add(staffButton);
        this.add(label);

    }

    private static class ButtonChoseModel implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            // 关闭窗口
            JButton jButton = (JButton) e.getSource();
            Container container = jButton.getParent();
            while (!(container instanceof JFrame)) {
                container = container.getParent();
            }
            ((JFrame)container).dispose();

            if (USER.equals(e.getActionCommand())) {
                new UserFrame().start();
            } else if (STAFF.equals(e.getActionCommand())) {
                new StaffFrame().start();
            }
        }
    }


}
